<template>
  <div class="container">
    <topTitle
      :titleText="titleText"
      :back="back"
      @gobackTriser="resetForm"
    ></topTitle>
    <div class="mainCon">
      <el-form
        :model="ruleForm"
        :rules="rules"
        label-width="100px"
        class="demo-ruleForm"
        ref="ruleForm"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="单位类型" prop="departmentType">
              <el-select
                v-model.trim="ruleForm.departmentType"
                @change="departmentChange"
                clearable
                placeholder="请选择"
                :disabled="false"
              >
                <el-option label="企业" value="0"></el-option>
                <el-option label="事业单位" value="5"></el-option>
                <el-option label="个体工商户" value="15"></el-option>
                <el-option label="其他" value="10"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="ruleForm.departmentType == 0">
            <el-form-item label="企业类型" prop="companyType">
              <el-select
                v-model.trim="ruleForm.companyType"
                clearable
                filterable
                placeholder="请选择"
              >
                <el-option
                  v-for="item in companyTypeArr"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业所属行业" prop="industry">
              <el-cascader
                ref="industry"
                class="industrySelect"
                v-model="ruleForm.industry"
                :options="industryOptionsNC"
                filterable
                clearable
                @change="getIndustry"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业名称" prop="companyName">
              <el-input
                class="inputStyle"
                :disabled="true"
                v-model.trim="ruleForm.companyName"
                @blur="ruleForm.companyName = changeValue($event)"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="统一社会信用代码" prop="uscc">
              <el-input
                class="inputStyle"
                :disabled="true"
                v-model.trim="ruleForm.uscc"
                @blur="ruleForm.uscc = changeValue($event)"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-col :span="7" class="labelStyMin">
              <el-form-item label="注册登记地区" class="qyAtt" prop="belong">
                <!-- <el-input :disabled="false"  v-model = "enterpriseData.enterpriseBelongs"></el-input> -->
                <el-select
                  v-model.trim="ruleForm.belong"
                  placeholder="请选择"
                  @change="changeBelong"
                >
                  <el-option label="本地企业" value="1"></el-option>
                  <el-option label="外地企业" value="2"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="10" class="labelStyMax">
              <el-form-item label=" " class="qyReg" prop="regAddress">
                <!-- <el-input :disabled="false"  v-model = "enterpriseData.regAreaName"></el-input> -->
                <el-cascader
                  :key="isRegAreas"
                  ref="regAreas"
                  v-model.trim="ruleForm.regAddress"
                  :options="regAreasOptions"
                  @change="handerChange"
                  clearable
                  filterable
                  placeholder="请选择营业执照上的注册地址"
                ></el-cascader>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-form-item label="经营地区" prop="address">
              <el-cascader
                ref="manageAreas"
                class="areasSelect"
                v-model="ruleForm.address"
                :options="areasOptions"
                clearable
                filterable
                :disabled="isDisabled"
                placeholder="请选择企业在本地区经营场所地址"
              >
              </el-cascader>
              <!-- <el-input v-model="ruleForm.address" v-else placeholder="请选择企业在内蒙古经营场所地址" disabled class = "businessAds"></el-input> -->
              <!-- <el-input :disabled="false" class = "inputStyle"  v-model = "enterpriseData.bizAreaName"></el-input> -->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="ruleForm.departmentType == '0'">
          <el-col :span="12">
            <el-col :span="7" class="labelStyMin">
              <el-form-item label="法人姓名" prop="legalName">
                <el-input
                  :disabled="false"
                  v-model.trim="ruleForm.legalName"
                  clearable
                  @blur="ruleForm.legalName = changeValue($event)"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10" class="labelStyMax">
              <el-form-item label="法人联系方式" prop="legalPhoneNumber">
                <el-input
                  :disabled="false"
                  v-model.trim="ruleForm.legalPhoneNumber"
                  clearable
                  @blur="ruleForm.legalPhoneNumber = changeValue($event)"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法人身份证号" prop="numberId">
              <el-input
                :disabled="false"
                class="inputStyle"
                v-model.trim="ruleForm.numberId"
                clearable
                @blur="ruleForm.numberId = changeValue($event)"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-col :span="7" class="labelStyMin">
              <el-form-item label="联系人姓名" prop="transactor">
                <el-input
                  :disabled="false"
                  v-model.trim="ruleForm.transactor"
                  clearable
                  @blur="ruleForm.transactor = changeValue($event)"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10" class="labelStyMax">
              <el-form-item label="联系方式" prop="phoneNumber">
                <el-input
                  :disabled="false"
                  v-model.trim="ruleForm.phoneNumber"
                  clearable
                  @blur="ruleForm.phoneNumber = changeValue($event)"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="7" class="labelStyMin">
              <el-form-item label="座机号码">
                <el-input
                  :disabled="false"
                  v-model.trim="ruleForm.landlineTelHead"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10" class="labelStyMax">
              <el-form-item label=" ">
                <el-input
                  :disabled="false"
                  v-model.trim="ruleForm.landlineTelNum"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系邮箱" prop="email">
              <el-input
                :disabled="false"
                class="inputStyle"
                v-model.trim="ruleForm.email"
                clearable
                @blur="ruleForm.email = changeValue($event)"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="本地详细办公地址">
              <el-input
                :disabled="false"
                class="inputStyle"
                placeholder="请输入"
                v-model.trim="enterpriseData.officeAddress"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="!isYiLingUser()">
          <el-col :span="12">
            <el-form-item label="账号用户名">
              <el-input
                :disabled="true"
                class="inputStyle"
                v-model.trim="ruleForm.username"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="企业密保手机号（可用于企业找回账号密码)"
              prop="phone"
            >
              <el-input
                :disabled="false"
                class="inputStyle"
                placeholder="用于接收审核结果和后期账号安全设置"
                v-model.trim="ruleForm.phone"
                clearable
                @blur="ruleForm.phone = changeValue($event)"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <template v-if="isYiLingUser()">
          <el-row>
            <el-col :span="12">
              <el-form-item label="劳资负责人姓名">
                <el-input
                  class="inputStyle"
                  v-model.trim="enterpriseData.laborSupervisor"
                  placeholder="请输入"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="劳资负责人电话">
                <el-input
                  class="inputStyle"
                  v-model.trim="enterpriseData.laborSupervisorTel"
                  placeholder="请输入"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="监管人员姓名">
                <el-input
                  class="inputStyle"
                  v-model.trim="enterpriseData.supervisor"
                  placeholder="请输入"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="监管人员电话">
                <el-input
                  class="inputStyle"
                  v-model.trim="enterpriseData.supervisorTel"
                  placeholder="请输入"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </template>
        <el-row>
          <el-col :span="24">
            <el-form-item label="认证资料" v-if="!isUploadCredential">
              <ul class="clearfix" v-if="enterpriseData.departmentType == '0'">
                <li
                  class="fl picBox"
                  v-for="(item, i) of enterpriseData.fileExpandVOs"
                  :key="i"
                >
                  <!-- <img :src="item.url" alt="" class = "imgStyle"> -->
                  <div class="picStyle">
                    <el-image
                      class="imgStyle"
                      :src="item.url"
                      :preview-src-list="srcList"
                      @click="enlargeImg(i)"
                    >
                    </el-image>
                  </div>
                  <p v-if="i == 0" class="picTipStyle">营业执照</p>
                  <p v-if="i == 1" class="picTipStyle">法人身份证正面</p>
                  <p v-if="i == 2" class="picTipStyle">法人身份证反面</p>
                </li>
              </ul>
              <ul class="clearfix" v-else>
                <li
                  class="fl picBox"
                  v-for="(item, i) of enterpriseData.fileExpandVOs"
                  :key="i"
                >
                  <!-- <img :src="item.url" alt="" class = "imgStyle"> -->
                  <div class="picStyle" v-if="i == 0">
                    <el-image
                      class="imgStyle"
                      :src="item.url"
                      :preview-src-list="srcList"
                      @click="enlargeImg(i)"
                    >
                    </el-image>
                  </div>
                  <p v-if="i == 0" class="picTipStyle">单位登记证书</p>
                </li>
              </ul>
            </el-form-item>
            <el-form-item
              v-if="isUploadCredential && departmentType == '0'"
              label="认证资料"
              prop="fileImg"
              class="imgLabel"
            >
              <ul class="imgBoxs clearfix">
                <li class="imgBox">
                  <div class="imgTopBox">
                    <el-tooltip
                      class="item"
                      effect="dark"
                      content="点击上传图片"
                      placement="bottom"
                    >
                      <form class="uploadBtn" id="licenseForm">
                        <input
                          type="file"
                          name="file"
                          id="licenseFile"
                          accept="image/png, image/jpeg, image/jpg"
                          @change="
                            uploadImg(
                              'licenseFile',
                              0,
                              'licenseForm',
                              'LICENSE'
                            )
                          "
                        />
                        <i class="el-icon-plus"></i>
                        <img :src="file[0].imgSrc" v-show="file[0].isShow" />
                      </form>
                    </el-tooltip>
                    <div class="imgName">企业营业执照</div>
                  </div>
                </li>
                <li class="imgBox">
                  <div class="imgTopBox">
                    <el-tooltip
                      class="item"
                      effect="dark"
                      content="点击上传图片"
                      placement="bottom"
                    >
                      <form class="uploadBtn" id="idcardForm1">
                        <input
                          type="file"
                          name="file"
                          id="idcardFront"
                          accept="image/png, image/jpeg, image/jpg"
                          @change="
                            uploadImg(
                              'idcardFront',
                              1,
                              'idcardForm1',
                              'IDCARDFRONT'
                            )
                          "
                        />
                        <i class="el-icon-plus"></i>
                        <img :src="file[1].imgSrc" v-show="file[1].isShow" />
                      </form>
                    </el-tooltip>
                    <div class="imgName">法人身份证正面</div>
                  </div>
                </li>
                <li class="imgBox">
                  <div class="imgTopBox">
                    <el-tooltip
                      class="item"
                      effect="dark"
                      content="点击上传图片"
                      placement="bottom"
                    >
                      <form class="uploadBtn" id="idcardForm2">
                        <input
                          type="file"
                          name="file"
                          id="idcardBack"
                          accept="image/png, image/jpeg, image/jpg"
                          @change="
                            uploadImg(
                              'idcardBack',
                              2,
                              'idcardForm2',
                              'IDCARDBACK'
                            )
                          "
                        />
                        <i class="el-icon-plus"></i>
                        <img :src="file[2].imgSrc" v-show="file[2].isShow" />
                      </form>
                    </el-tooltip>
                    <div class="imgName">法人身份证反面</div>
                  </div>
                </li>
              </ul>
              <div class="imgRemind">{{ imgRemind }}</div>
            </el-form-item>
            <el-form-item
              v-else-if="isUploadCredential && departmentType != '0'"
              label="认证资料"
              prop="fileImg"
              class="imgLabel"
            >
              <ul class="imgBoxs clearfix">
                <li class="imgBox">
                  <div class="imgTopBox">
                    <el-tooltip
                      class="item"
                      effect="dark"
                      content="点击上传图片"
                      placement="bottom"
                    >
                      <form class="uploadBtn" id="licenseForm_card">
                        <input
                          type="file"
                          name="file"
                          id="licenseFile_card"
                          accept="image/png, image/jpeg, image/jpg"
                          @change="
                            uploadImg(
                              'licenseFile_card',
                              0,
                              'licenseForm_card',
                              'LICENSE'
                            )
                          "
                        />
                        <i class="el-icon-plus"></i>
                        <img :src="file[0].imgSrc" v-show="file[0].isShow" />
                      </form>
                    </el-tooltip>
                    <div class="imgName">单位登记证书</div>
                  </div>
                </li>
              </ul>
              <div class="imgRemind">{{ imgRemind }}</div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item class="submitBox">
          <el-button
            type="primary"
            @click.native="submitForm('ruleForm')"
            v-show="isShowUpdate"
            class="commonBut saveBtn"
            :loading="saveLoading"
            >保存</el-button
          >
          <el-button @click.native="resetForm('ruleForm')" class="commonBut"
            >取消</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import common from '../../kits/common'

import { mapState, mapActions } from 'vuex'
export default {
  name: 'jcEnterpriseInfo',
  data() {
    //验证企业名称--
    var validateName = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('企业名称不能为空'))
      } else {
        if (value.length > 100) {
          callback(new Error('企业名称不能超过100个字符'))
        } else {
          // if (this.ruleForm.uscc !== "") {
          //   this.$refs["ruleForm"].validateField("uscc");
          // }
          callback()
        }
      }
    }
    //验证uscc
    var validateUscc = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('统一社会信用代码不能为空'))
      } else {
        var regUscc = /^[0-9A-Z]{2}[0-9]{6}[0-9A-Z]{10}$/
        if (!regUscc.test(value)) {
          callback(new Error('统一社会信用代码格式不正确'))
        } else {
          callback()
          // this.axios({
          //   method: "post",
          //   url: "/api-c/company/expand/validuscc", //api-c/companyaudit/base/validcompanyuscc
          //   data: {
          //     companyName: this.ruleForm.companyName,
          //     uscc: this.ruleForm.uscc
          //   }
          // })
          //   .then(
          //     res => {
          //       if (!res.data.hasError) {
          //         callback();
          //       } else {
          //         callback(new Error(res.data.errorMsg));
          //       }
          //     },
          //     response => {
          //       callback(new Error("验证失败"));
          //     }
          //   )
          // .catch(error => {
          //   this.saveLoading = false;
          //   this.isValidUscc = "1";
          //   callback(new Error("验证失败"));
          // });
        }
      }
    }

    var enterpriseName = (rule, value, callback) => {
      if (value === null) {
        value = 0
      } else {
        value = value.replace(/\s+/g, '')
      }
      if (value !== '' || value != 0) {
        if (value.length < 2 || value.length > 20) {
          callback(new Error('请输入正确的姓名'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    // var validatorTelHead = (rule, value, callback) =>{
    //     if(value && (this.ruleForm.landlineTelNum == "" || this.ruleForm.landlineTelNum == null)) {
    //          callback(new Error("请填写完整的座机号码"));
    //     }
    // };
    // var validatorTelNum = (rule, value, callback) =>{
    //     if(value && (this.ruleForm.landlineTelHead == "" || this.ruleForm.landlineTelHead == null)) {
    //          callback(new Error("请填写完整的座机号码"));
    //     }
    // }
    return {
      titleText: '企业信息',
      companyTypeArr: [], //企业类型
      back: true,
      ruleForm: {
        // salaryDay: "",
        numberId: '', //验证身份证号
        phoneNumber: '', //验证手机号
        legalPhoneNumber: '', //法人验证手机号
        legalName: '', //法人名称
        companyName: '', //企业名称
        uscc: '', //统一社会信用代码
        industry: '',
        scale: '',
        belong: '1',
        regAddress: '',
        address: '',
        phone: '',
        email: '',
        landlineTelHead: '',
        landlineTelNum: '',
        transactor: '',
        srcList: [],
        oldSrcList: [],
        departmentType: '',
        companyType: '',
        username: '',
      },
      rules: {
        companyName: [
          { required: true, validator: validateName, trigger: 'blur' },
        ],
        uscc: [{ required: true, validator: validateUscc, trigger: 'blur' }],
        industry: [
          { required: true, message: '请选择行业', trigger: 'change' },
        ],
        companyType: [
          { required: true, message: '请选择企业类型', trigger: 'change' },
        ],
        departmentType: [
          { required: true, message: '请选择单位类型', trigger: 'change' },
        ],
        belong: [
          { required: true, message: '请选择企业归属', trigger: 'change' },
        ],
        regAddress: [
          { required: true, message: '请选择注册地址', trigger: 'change' },
        ],
        address: [
          { required: true, message: '请输入经营地址', trigger: 'change' },
        ],
        phone: [
          { required: true, message: '请输入密保手机号', trigger: 'blur' },
          {
            pattern: /^1[3456789]\d{9}$/,
            message: '手机号格式不正确',
            trigger: 'blur',
          },
        ],

        // salaryDay: [
        //   { required: true, message: "请选择工资发放日", trigger: "change" }
        // ],
        numberId: [
          {
            pattern:
              /^(([1-9][0-9]{5}(19|20)[0-9]{2}((0[1-9])|(1[0-2]))([0-2][1-9]|10|20|30|31)[0-9]{3}([0-9]|X|x))|([1-9][0-9]{5}[0-9]{2}((0[1-9])|(1[0-2]))([0-2][1-9]|10|20|30|31)[0-9]{3}))$/,
            message: '请输入正确的身份证号',
            trigger: 'blur',
          },
        ],
        phoneNumber: [
          {
            pattern: /^1[3456789]\d{9}$/,
            message: '请输入正确的手机号码',
            trigger: 'blur',
          },
        ],
        legalPhoneNumber: [
          {
            pattern: /^1[3456789]\d{9}$/,
            message: '请输入正确的手机号码',
            trigger: 'blur',
          },
        ],
        email: [
          {
            pattern: /^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/,
            message: '请输入正确的邮箱地址',
            trigger: 'blur',
          },
        ],
        legalName: [
          {
            trigger: 'blur',
            validator: enterpriseName,
          },
        ],
        transactor: [
          {
            trigger: 'blur',
            validator: enterpriseName,
          },
        ],
        // landlineTelHead:[{
        //     validator: validatorTelHead,
        //     trigger: "blur"
        // }],
        // landlineTelNum:[{
        //     validator: validatorTelNum,
        //     trigger: "blur"
        // }]
      },
      enterpriseData: '', //企业信息
      enterpriseScale: [
        // {
        //   //企业规模
        //   value: "01",
        //   label: "1-50人"
        // },
        // {
        //   value: "02",
        //   label: "51-100人"
        // },
        // {
        //   value: "03",
        //   label: "101-200人"
        // },
        // {
        //   value: "04",
        //   label: "201-500人"
        // },
        // {
        //   value: "05",
        //   label: "501-1000人"
        // },
        // {
        //   value: "06",
        //   label: "1000人以上"
        // }
      ],
      outAreasOptions: [], //省外省市
      neiAreasOptions: [], //内蒙省市
      regAreasOptions: [], //注册地址
      areasOptions: [], //经营地址
      regAreas: {
        regAreaId: '', //注册地址全id
        // regAreaName: "", //注册地址全名称
        // regProvinceId: "", //注册地址省id
        // regProvinceName: "", //注册地址省名称
        // regCityId: "", //注册地址市id
        // regCityName: "", //注册地址市名称
        // regCountyId: "", //注册地址区id
        // regCountyName: "" //注册地址区名称
      },
      manageAreas: {
        bizAreaId: '', //经营地址全id
        // bizAreaName: "", //经营地址全名称
        // bizCityId: "", //经营地址市id
        // bizCityName: "", //经营地址市名称
        // bizCountyId: "", //经营地址区id
        // bizCountyName: "" //经营地址区名称
      },
      srcList: [],
      oldSrcList: [],
      saveLoading: false,
      isValidUscc: '',
      isRegAreas: 0, //使用el-cascader"报错TypeError: Cannot read property 'level' of null"的解决
      isDisabled: true,
      isShowUpdate: '',
      file: [
        {
          //上传图片
          originalName: '', //原文件名
          imgId: '', //图片id
          newName: 'LICENSE', //新文件名(营业执照)
          FileSize: '', //文件大小
          FileType: '', //文件类型
          relativePath: '', //文件相对路径
          imgSrc: '', //文件绝对路径
          isShow: false,
        },
        {
          originalName: '', //原文件名
          imgId: '', //图片id
          newName: 'IDCARDFRONT', //新文件名(身份证)
          FileSize: '', //文件大小
          FileType: '', //文件类型
          relativePath: '', //文件相对路径
          imgSrc: '', //文件绝对路径
          isShow: false,
        },
        {
          originalName: '', //原文件名
          imgId: '', //图片id
          newName: 'IDCARDBACK', //新文件名(身份证)
          FileSize: '', //文件大小
          FileType: '', //文件类型
          relativePath: '', //文件相对路径
          imgSrc: '', //文件绝对路径
          isShow: false,
        },
      ],
      imgRemind: '', //图片上传不完整的提示
      isUploadCredential: false,
      departmentType: '',
    }
  },
  computed: { ...mapState(['industryOptionsNC']) },
  created() {
    //获取全国省市除内蒙
    this.selectOutAreas()
    //获取行业
    this.getIndustryNC({})
    this.getTypeList()
    //获取内蒙省市
    this.selectNeiAreas()
    this.isShowUpdate =
      this.$store.state.buttonLimitsArr.indexOf('companyMaintain:update') > -1
    // 获取企业规模
    this.getScaleSelct()
  },
  methods: {
    // 字典
    getTypeList() {
      return this.axios({
        method: 'get',
        params: {
          type: 'NC_COMPANY_TYPE',
        },
        url: 'api-c/companyaudit/expand/getcompanytype',
      })
        .then((response) => {
          if (!response.data.hasError) {
            this.companyTypeArr = response.data.result
          } else {
            this.$message.error(response.data.errorMsg)
          }
        })
        .catch((error) => {
          if (error.response) {
            this.$message.error(error.response.data)
          }
        })
    },
    ...mapActions(['getIndustryNC']),
    //   编辑
    // editInfo() {
    //   this.false = false;
    //   this.isShowSubmit = true;
    // },
    // 取消
    resetForm(formName) {
      // this.$emit("changeHasShowSelf", false);
      // this.$emit("changeHasInfo", true);
      let oldUrl = '/home/enterpriseBasicInfo/infoMaintain'
      let path = '/home/enterpriseSet/enterpriseDetail'
      let name = 'enterpriseDetail'
      const { companyId, companyName } = this.$route.query
      let query = { companyId }
      if (this.isYiLingUser()) {
        oldUrl = '/home/enterpriseArchives/enterpriseList'
        path = '/home/enterpriseArchives/enterpriseData'
        name = 'enterpriseData'
        Object.assign(query, { companyName, uscc: this.enterpriseData.uscc })
      }
      this.$router.push({ path, name, query })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl,
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    // 获取企业信息
    getEnterpriseInfo() {
      this.axios({
        method: 'post',
        url: 'api-c/company/expand/companies',
        data: {
          id: this.$route.query.companyId,
          areaId: this.$store.state.areaInfoArr.areaId,
        },
      })
        .then((res) => {
          this.enterpriseData = res.data.result
          if (this.enterpriseData.belongs == '1') {
            this.regAreasOptions = this.neiAreasOptions
          } else {
            this.regAreasOptions = this.outAreasOptions
          }
          this.ruleForm.companyName = this.enterpriseData.name
          this.ruleForm.uscc = this.enterpriseData.uscc
          // this.ruleForm.industry =  this.enterpriseData.industryId;
          this.ruleForm.industry = this.enterpriseData.industryList
          this.ruleForm.belong = this.enterpriseData.belongs
          this.ruleForm.regAddress = this.enterpriseData.regAreaId
          // this.ruleForm.regAddress = this.getFathersById(this.enterpriseData.regAreaId,this.regAreasOptions,"value");
          if (this.ruleForm.belong == '2') {
            this.isDisabled = false
            // this.ruleForm.address = this.enterpriseData.bizAreaId;
          } else if (this.ruleForm.belong == '1') {
            this.isDisabled = true
          }
          this.ruleForm.address = this.enterpriseData.bizAreaId
          this.ruleForm.legalName = this.enterpriseData.boss //法人姓名
          this.ruleForm.legalPhoneNumber = this.enterpriseData.bossTel //法人联系方式
          this.ruleForm.numberId = this.enterpriseData.bossIdcard //法人身份证号
          this.ruleForm.phoneNumber = this.enterpriseData.transactorTel // 企业联系电话
          // this.ruleForm.salaryDay = this.enterpriseData.salaryDay; // 工资发放日
          this.ruleForm.scale = this.enterpriseData.scale //企业规模
          this.ruleForm.phone = this.enterpriseData.tel //密保手机号
          this.ruleForm.email = this.enterpriseData.email
          this.ruleForm.landlineTelHead = this.enterpriseData.landlineTelHead
          this.ruleForm.landlineTelNum = this.enterpriseData.landlineTelNum
          this.ruleForm.transactor = this.enterpriseData.transactor
          if (res.data.result.departmentType == '0') {
            this.ruleForm.companyType = this.enterpriseData.companyType
          } else {
            this.ruleForm.companyType = ''
          }

          this.ruleForm.departmentType = this.enterpriseData.departmentType + ''
          // if(this.enterpriseData.departmentType=="0"){
          //   this.isUploadCredential=false;
          // }else{
          //   this.isUploadCredential=true;
          // }
          this.ruleForm.username = this.enterpriseData.username
          for (var i = 0; i < this.enterpriseData.fileExpandVOs.length; i++) {
            this.srcList.push(this.enterpriseData.fileExpandVOs[i].url)
            this.oldSrcList.push(this.enterpriseData.fileExpandVOs[i].url)
          }
          this.$nextTick(() => {
            this.$refs.ruleForm.clearValidate()
          })
        })
        .catch((error) => {})
    },
    enlargeImg(index) {
      this.srcList = this.oldSrcList
      var demo = this.srcList
      var frontArr = demo.slice(0, index)
      var behindArr = demo.slice(index, demo.length)
      var list = behindArr.concat(frontArr)
      this.srcList = list
    },
    submitForm(formName) {
      this.saveLoading = true
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.isUploadCredential) {
            var isOk = 0
            for (var i = 0; i < this.file.length; i++) {
              if (!this.file[i].imgSrc) {
                isOk++
              }
            }
            if (isOk > 0 && this.ruleForm.departmentType === '0') {
              this.imgRemind = '请上传三张图片'
              this.saveLoading = false
              return false
            } else if (
              isOk > 0 &&
              isOk !== 2 &&
              (this.ruleForm.departmentType === '5' ||
                this.ruleForm.departmentType === '10')
            ) {
              this.imgRemind = '请上传登记书照片'
              this.saveLoading = false
              return false
            }
          }
          //获取行业
          this.getIndustry()
          //获取注册地址的省市区
          // this.getRegAddress();
          //获取经营地址的市区
          // this.getManageAddress();
          if (
            (this.ruleForm.landlineTelHead &&
              (this.ruleForm.landlineTelNum == '' ||
                this.ruleForm.landlineTelNum == null)) ||
            (this.ruleForm.landlineTelNum &&
              (this.ruleForm.landlineTelHead == '' ||
                this.ruleForm.landlineTelHead == null))
          ) {
            this.$message({
              type: 'error',
              message: '请填写完整的座机号码',
            })
            return false
          }
          if (
            this.ruleForm.landlineTelHead == null ||
            this.ruleForm.landlineTelNum == null
          ) {
            this.ruleForm.landlineTelHead = ''
            this.ruleForm.landlineTelNum = ''
          }
          let regAreaId = ''
          if (Array.isArray(this.ruleForm.regAddress)) {
            regAreaId =
              this.ruleForm.regAddress.length > 1
                ? this.ruleForm.regAddress[this.ruleForm.regAddress.length - 1]
                : this.ruleForm.regAddress[0]
          } else {
            regAreaId = this.ruleForm.regAddress
          }
          let bizAreaId = ''
          if (Array.isArray(this.ruleForm.address)) {
            bizAreaId =
              this.ruleForm.address.length > 1
                ? this.ruleForm.address[this.ruleForm.address.length - 1]
                : this.ruleForm.address[0]
          } else {
            bizAreaId = this.ruleForm.address
          }
          let data = {
            userId: 2,
            id: this.enterpriseData.id,
            scale: this.ruleForm.scale,
            name: this.ruleForm.companyName,
            companyType: this.ruleForm.companyType,
            uscc: this.ruleForm.uscc,
            boss: this.ruleForm.legalName,
            bossTel: this.ruleForm.legalPhoneNumber,
            bossIdcard: this.ruleForm.numberId,
            transactor: this.ruleForm.transactor,
            transactorTel: this.ruleForm.phoneNumber,
            landlineTel:
              this.ruleForm.landlineTelHead +
              '-' +
              this.ruleForm.landlineTelNum,
            landlineTelHead: this.ruleForm.landlineTelHead,
            landlineTelNum: this.ruleForm.landlineTelNum,
            email: this.ruleForm.email,
            officeAddress: this.enterpriseData.officeAddress,
            industryId: this.ruleForm.industry,
            regAreaId: regAreaId, // --注册地址全id
            bizAreaId: bizAreaId, //   ---经营地址全id
            tel: this.ruleForm.phone,
            belongs: this.ruleForm.belong,
            departmentType: this.ruleForm.departmentType,
            fileVOs: this.isUploadCredential ? this.getImg() : '',
          }
          this.isYiLingUser() &&
            Object.assign(data, {
              laborSupervisor: this.enterpriseData.laborSupervisor,
              laborSupervisorTel: this.enterpriseData.laborSupervisorTel,
              supervisor: this.enterpriseData.supervisor,
              supervisorTel: this.enterpriseData.supervisorTel,
            })
          this.axios({
            method: 'post',
            url: 'api-c/company/expand/companies/edit',
            data,
          })
            .then((res) => {
              this.saveLoading = false
              if (!res.data.hasError) {
                this.$message({
                  type: 'success',
                  message: '保存成功',
                })
                this.resetForm(formName)
              } else {
                this.$message({
                  type: 'error',
                  message: response.data.errorMsg,
                })
              }
            })
            .catch((error) => {})
        } else {
          if (this.isValidUscc == '1') {
            this.$message({
              showClose: true,
              duration: 3000,
              message: '统一社会信用代码验证失败',
              type: 'error',
            })
          }
          this.saveLoading = false
          return false
        }
      })
    },
    //获取所属行业
    getIndustry() {
      if (this.ruleForm.industry.length > 0) {
        this.ruleForm.industry =
          this.$refs.industry.getCheckedNodes()[0].path[1]
      }
    },
    //获取内蒙省市
    selectNeiAreas() {
      let vm = this
      //（本省：1，外省：2）
      vm.axios({
        method: 'post',
        url: 'api-bs/areadic/base/areas',
        data: {
          belongs: 1,
          areaId: this.$store.state.areaInfoArr.areaId,
        },
      })
        .then((res) => {
          this.getEnterpriseInfo()
          //内蒙省市
          vm.neiAreasOptions = res.data.result
          vm.regAreasOptions = res.data.result
          vm.areasOptions = res.data.result
        })
        .catch((error) => {
          this.$message({
            showClose: true,
            duration: 0,
            message: '获取区域数据失败',
            type: 'error',
          })
        })
    },
    //获取省外省市
    selectOutAreas() {
      let vm = this
      //（本省：1，外省：2）
      vm.axios({
        method: 'post',
        url: 'api-bs/areadic/base/areas',
        data: {
          belongs: 2,
          areaId: this.$store.state.areaInfoArr.areaId,
        },
      }).then(
        (res) => {
          vm.outAreasOptions = res.data.result
          this.getEnterpriseInfo()
        },
        (response) => {
          this.$message({
            showClose: true,
            duration: 0,
            message: '获取区域数据失败',
            type: 'error',
          })
        }
      )
    },
    //改变企业归属
    changeBelong(value) {
      //（本省：1，外省：2）
      ++this.isRegAreas
      if (value === '1') {
        this.isDisabled = true
        this.regAreasOptions = this.neiAreasOptions
      } else {
        this.isDisabled = false
        this.regAreasOptions = this.outAreasOptions
      }
      this.ruleForm.regAddress = ''
    },
    //本省企业经营地址等于注册地址
    handerChange(item) {
      if (this.ruleForm.regAddress.length > 0) {
        if (this.ruleForm.belong === '1') {
          let regAreaArray = this.$refs.regAreas.getCheckedNodes()[0].path
          this.ruleForm.address = regAreaArray
        } else {
          this.ruleForm.address = ''
        }
      }
    },
    departmentChange(val) {
      this.departmentType = val
      this.isUploadCredential = true
      this.ruleForm.companyType = ''
    },
    //图片上传
    ajaxUpload(formName, index, imgName) {
      var vm = this
      var options = {
        url: common.uploadUrl + 'api-f/files/upload',
        type: 'post',
        dataType: 'json',
        success: function (data) {
          vm.file[index].originalName = data.name
          vm.file[index].imgId = data.id
          vm.file[index].newName = data.id + imgName
          vm.file[index].FileSize = data.size
          vm.file[index].FileType = data.contentType
          vm.file[index].relativePath = data.path
          vm.file[index].imgSrc = data.url
          vm.file[index].isShow = true
        },
        error: function () {
          vm.$message({
            showClose: true,
            duration: 3000,
            message: '图片上传失败',
            type: 'error',
          })
        },
      }
      $('#' + formName).ajaxSubmit(options)
      return false
    },
    //上传图片
    uploadImg(inputId, index, formName, imgName) {
      var vm = this
      var fileName
      var file
      var fileSize
      try {
        fileName = $('#' + inputId).val()
        file = $('#' + inputId)[0].files[0]
        fileSize = (file.size / 1024).toFixed(0)
      } catch (e) {
        this.$message({
          message:
            '您的浏览器暂不支持计算上传文件的大小，确保上传文件不要超过5M，建议使用FireFox、Chrome或IE10以上浏览器。',
          type: 'warning',
        })
      }
      if (fileName) {
        //判断图片类型
        if (!/\.(jpg|jpeg|png|JPG|PNG)$/.test(fileName)) {
          vm.$message({
            showClose: true,
            duration: 3000,
            message: '图片类型必须是jpeg，jpg，png中的一种',
            type: 'error',
          })
          $('#' + inputId).val('')
          return
        }
        //判断图片大小
        if (fileSize / 1 > 1024 * 5) {
          vm.$message({
            showClose: true,
            duration: 3000,
            message: '图片大小不能超过5M',
            type: 'error',
          })
          $('#' + inputId).val('')
          return
        }
        vm.ajaxUpload(formName, index, imgName)
      }
    },
    //获取图片数组
    getImg() {
      let vm = this
      const fileArray = new Array()
      for (var j = 0; j < vm.file.length; j++) {
        fileArray[j] = {
          originalName: vm.file[j].originalName,
          newName: vm.file[j].imgId + vm.file[j].newName,
          FileSize: vm.file[j].FileSize,
          FileType: vm.file[j].FileType,
          relativePath: vm.file[j].relativePath,
        }
      }
      return JSON.stringify(fileArray)
    },
    // 获取企业规模
    getScaleSelct() {
      let vm = this
      vm.axios({
        method: 'post',
        url: '/api-bs/base/dicitem/typeorname',
        data: {
          dicitemType: 'ENTERPRISE_SCALE',
        },
      })
        .then(
          (res) => {
            //验证码失败
            if (!res.data.hasError) {
              this.enterpriseScale = res.data.result
            } else {
              this.$message({
                showClose: true,
                duration: 1000,
                message: '获取企业规模失败',
                type: 'error',
              })
            }
          },
          (res) => {
            this.$message({
              showClose: true,
              duration: 1000,
              message: '获取企业规模失败',
              type: 'error',
            })
          }
        )
        .catch((error) => {})
    },
  },
}
</script>
<style scoped lang="less">
.container {
  .mainCon {
    // width:100%;
    top: 198px;
    .labelStyMin {
      padding-left: 0px !important;
      min-width: 130px;
    }
    .labelStyMax {
      padding-left: 0px !important;
      margin-left: 5px;
      min-width: 155px;
    }
    .submitBox {
      text-align: center;
      margin-top: 40px;
      margin-bottom: 40px !important;
    }
    .picBox {
      margin-right: 60px;
      .picStyle {
        width: 116px;
        height: 116px;
        .imgStyle {
          width: 100%;
          height: 100%;
        }
      }
      .picTipStyle {
        text-align: center;
      }
    }

    /deep/ .el-row {
      margin-left: 10% !important;
    }
  }
  .demo-ruleForm {
    /deep/.imgLabel {
      label:before {
        content: '*';
        color: #f56c6c;
        margin-right: 4px;
      }
      .imgRemind {
        color: #f56c6c;
        font-size: 12px;
        line-height: 1;
      }
    }
  }
  .el-row {
    margin-bottom: 15px;
    &:last-child {
      margin-bottom: 0;
    }
    // .industrySelect {
    //     width: 361px;
    // }
    // .areasSelect{
    //     width: 361px;
    // }
  }

  .bg-purple {
    background: #d3dce6;
  }

  .row-bg {
    padding: 10px 0;
    background-color: #fff;
  }
  .inputStyle {
    width: 70%;
    min-width: 280px;
    height: 36px;
  }
  .el-form-item {
    margin-bottom: 0px !important;
  }
  /deep/ .el-form-item__label {
    float: inherit !important;
  }
  /deep/ .el-form-item__content {
    margin-left: 0 !important;
  }

  .el-button--primary {
    background-color: #009588;
    border-color: #009588;
  }
  .el-select {
    width: 70% !important;
  }
  .el-cascader {
    width: 70% !important;
  }
  .qyAtt .el-select {
    width: 100% !important;
  }
  .qyReg .el-cascader {
    width: 100% !important;
  }
  .qyReg {
    /deep/ label::before {
      content: '' !important;
    }
  }
  .businessAds {
    width: 70%;
  }
  //上传图片样式
  .imgBoxs {
    .imgBox {
      text-align: center;
      float: left;
      margin-right: 15px;
      font-size: 12px;
      .imgTopBox {
        width: 104px;
        height: 104px;
        border: 1px dotted #d4dae6;
        position: relative;
        background-color: #f5f7fb;
        .uploadBtn {
          width: 102px;
          height: 73px;
          cursor: pointer;
          input {
            opacity: 0;
            position: absolute;
            left: 0;
            top: 0;
            z-index: 100;
            height: 74px;
            width: 104px;
          }
          i {
            line-height: 74px;
            font-size: 25px;
            color: #b5b6b7;
          }
          img {
            width: 102px;
            height: 73px;
            position: absolute;
            top: 0;
            left: 0;
          }
        }
        .imgName {
          height: 30px;
          line-height: 30px;
          background: rgba(206, 206, 206, 0.3);
          color: #aaa;
        }
      }
    }
  }
}
</style>
